package com.jgy.cn.controller;

import com.jgy.cn.model.DetailLog;
import com.jgy.cn.service.AppUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.thymeleaf.util.StringUtils;

import java.util.List;

/**
 * @author jiangxs
 */
@Controller
@ResponseBody
@RequestMapping("/user")
@Api(value = "商城APP",tags = "商城APP")
public class TestController {
    @Autowired
    private AppUserService appUserService;

    /**
     * 查询用户钱包余额
     * @param userId
     * @return
     */
    @RequestMapping(value = "/getBalanceById",method = RequestMethod.POST)
    @ApiOperation(value = "查询用户钱包余额(根据用户ID)",notes = "查询用户钱包余额")
    public  String getBalanceById(@RequestBody String userId){
        // 默认获取用户ID值
        userId = "412734164814367856";
        return appUserService.getBalanceById(userId);
    }

    /**
     *
     * @param userId 默认
     * @param money 可以在页面传入
     * @param passWord 默认
     * @param type 默认2  消费  记录明细使用
     * @param name 可以传入 记录明细使用
     * @return
     * 必填: userId ,passWord ,type
     */
    @RequestMapping(value = "/changeMoney",method = RequestMethod.POST)
    @ApiOperation(value = "用户消费",notes = "用户消费100元的接口")
    public String changeMoney( String userId, String money,String passWord, String type, String name){
        if (StringUtils.isEmpty(money)) {
            money = "0";
        }
        // 默认获取用户ID值
        userId = "412734164814367856";
        // 默认密码
        passWord = "123456";
        type = "2";
        return appUserService.changeMoney(userId,passWord,money,type,name);
    }

    /**
     * 用户退款20元接口
     * @param userId 默认
     * @param type 用于判断退回位置  定义 1.退回app 2.退回银行卡
     * @param money 在页面传入需要退回金额
     * @param cardId 若有退回银行卡必填
     * @return
     *
     * 必填: userId ,
     */
    @RequestMapping(value = "/refundById",method = RequestMethod.POST)
    @ApiOperation(value = "用户退款",notes = "用户退款20元接口")
    public String refundById(String userId,String type,String money, String cardId){
        userId = "412734164814367856";
        cardId = "2323433665345636";
        if (StringUtils.isEmpty(type)){ return "请选择退回方式";}
        // 1.退回app 2.退回银行卡
        if ("1".equals(type)) {
            return appUserService.refundByIdAnd1(userId,money);
        } else if (!StringUtils.isEmpty(cardId)){
            return appUserService.refundByIdAnd2(userId,money,cardId);
        }
        return "返回数据不满足执行条件";
    }


    /**
     *
     * @param userId 获取用户信息
     * @return
     */
    @RequestMapping(value = "/detailedById",method = RequestMethod.POST)
    @ApiOperation(value = "查询用户钱包金额变动明细",notes = "查询用户钱包金额变动明细的接口")
    public List<DetailLog> detailedById(@RequestBody String userId){
        userId = "412734164814367856";
        return appUserService.detailedById(userId);
    }

}
